<?php

abstract class Solphr_SimpleAction {
	const OPT_AUTOCOMMIT = 1001;
	const OPT_ALLOWDUPS = 1002;
	const OPT_WAITFLUSH = 1003;
	const OPT_WAITSEARCHER = 1004;

	protected $autoCommit = false;
	protected $allowDups = false;
	protected $waitFlush = true;
	protected $waitSearcher = true;
	
	protected $queryItems = array();
	protected $req;

	public function __construct($URL, $httpMethod = Solphr_Request_Interface::POST) {
		$class = Solphr_Request_Interface::IMPL;
		$this->req = new $class($URL, $httpMethod);
	}
	
	public function setOption($option, $value) {
		switch($option) {
			case self::OPT_AUTOCOMMIT:
				$this->autoCommit = (bool)$value;
				break;
			case self::OPT_ALLOWDUPS:
				$this->allowDups = (bool)$value;
				break;
			case self::OPT_WAITFLUSH:
				$this->waitFlush = (bool)$value;
				break;
			case self::OPT_WAITSEARCHER:
				$this->waitSearcher = (bool)$value;
				break;
		}
	}
	
	public function commit() {
		$req = '<commit';
		if($this->waitFlush === false) {
			$req .= ' waitFlush="false"';
		} 
		if($this->waitSearcher === false) {
			$req .= ' waitSearcher="false"';
		}
		$req .= '/>'; 
		
		$this->req->setDataFromString($req, true);
		return $this->req->commit(); 
	}
	
	public function optimize() {
		$req = '<optimize';
		if($this->waitFlush === false) {
			$req .= ' waitFlush="false"';
		} 
		if($this->waitSearcher === false) {
			$req .= ' waitSearcher="false"';
		}
		$req .= '/>'; 
		
		$this->req->setDataFromString($req, true);
		return $this->req->commit(); 
	}
	
}